import java.util.Comparator;
import java.util.PriorityQueue;

class IntCmp1 implements Comparator<Integer> {

    @Override
    public int compare(Integer o1, Integer o2) {
        return o2.compareTo(o1);
    }

}
public class Testnew {
    public int[] smallestK(int[] arr, int k) {
        int[] ret = new int[k];
        if(k == 0||arr == null){
            return ret;
        }
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>(new IntCmp1());
        for(int i = 0;i<k;i++){
            priorityQueue.offer(arr[i]);
        }
        for(int i = k;i<arr.length;i++){
            int tmp = priorityQueue.peek();
            if(tmp>arr[i]){
                priorityQueue.poll();
                priorityQueue.offer(arr[i]);
            }

        }
        for(int i = 0;i<k;i++){
            ret[i] = priorityQueue.poll();
        }
        return ret;

    }
    public int[] smallestK1(int[] arr, int k) {
        PriorityQueue<Integer> priorityQueue = new PriorityQueue<>();
        for(int i = 0;i<arr.length;i++){
            priorityQueue.offer(arr[i]);
        }
        int[] ret = new int[k];
        for(int i = 0;i<k;i++){
            ret[i] = priorityQueue.poll();
        }
        return ret;
    }
}
